<template>
  <div id="app">
    <router-view />
  </div>
</template>
<script>
import { isBind } from "api/Login"
import queryParams from "utils/getQueryVal";

export default {
  name: "App",
  data() {
    return {
      appData: {
        appid: "wx590b16a351494147",
        redirect_uri: encodeURIComponent("https://www.risesin.com/h5"),
        scope: "snsapi_userinfo"
      }
    }
  },
  mounted() {
    if (localStorage.openId && localStorage.openId != 'undefined') {
      return false;
    } else {
      localStorage.removeItem("openId");
    }

    let { appid, redirect_uri, scope } = this.appData
    const code = queryParams("code");
    if (code) {
      isBind(code, "1").then(({ data }) => {
        if (data) {
          localStorage.openId = data.openId; 
        }
      })
    } else {
      // 获取code
      window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=${scope}&state=STATE`
    }
  }
}
</script>
<style lang="stylus">
#app
  font-family PingFangSC-Regular,PingFang SC
  -webkit-font-smoothing antialiased
  -moz-osx-font-smoothing grayscale
</style>
<style>
*:not(input,textarea), *:before:not(input,textarea), *:after:not(input,textarea) {
    -webkit-user-select: none; 
  }
</style>
